/**
 * @param {number[]} arr
 */
 var MajorityChecker = function(arr) {
  this.res = arr
};

/** 
 * @param {number} left 
 * @param {number} right 
 * @param {number} threshold
 * @return {number}
 */
MajorityChecker.prototype.query = function(left, right, threshold) {
  let obj = new Map()
  let arr = this.res.slice(left,right+1)
  for(let i=0;i<arr.length;i++){
    obj.set(arr[i],obj.get(arr[i])+1 ||1)
  }
  for(let [key,value] of obj.entries){
    if(value==threshold)return key
  }
  return -1
};

/**
 * Your MajorityChecker object will be instantiated and called as such:
 * var obj = new MajorityChecker(arr)
 * var param_1 = obj.query(left,right,threshold)
 */